<!--
 * @description  :关联人员人员选择列表
 * @descriptionDetail:关联人员人员选择列表
 * @copyright    : 浙江烟草
 * @author       : dw
 * @create       : 2022-10-09 22:21:21
-->
<template>
	<view class="page">
		<!-- #ifdef H5-ONLY -->
		<theme-navbar :is-white="false" :title="navTitle" :custom-back="goBack" style="z-index: 99999">
			<view class="nav-right-icon">
				<view @tap="handlerSure">
					确定
				</view>
			</view>
		</theme-navbar>
		<!-- #endif -->
		<!-- #ifdef H5-WECHAT || H5-EMP -->
		 <fab-button :content="fContent" @fabtrigger="fabtrigger" />
		<!-- #endif -->
		<view class="nolicence-search-lay">
			<u-search shape="round" :clearabled="true" :showAction="true" actionText="确定" placeholder="姓名/电话/现住址" :animation="true" v-model="keyword" @custom="handlerSearch"></u-search>
		</view>
		<me-table :i="0" :top="102" :index="0" :load-data="loadData" :init-load="false" ref="mescrollItem0">
			<template #default="d">
				<view class="card">
					<u-row @tap="handlerSelectItem(d.data)">
						<u-col span="10">
							<list-item-person :itemInfo="d.data"></list-item-person>
						</u-col>
						<u-col span="2" style="text-align:right;">
							<u-icon name="checkbox-mark" color="#2979ff" size="38" style="margin-right: 10px;" v-if="selectedUids.includes(d.data.uuid)"></u-icon>
						</u-col>
					</u-row>
				</view>
			</template>
		</me-table>
		<view class="submit-btns btn-other-cls">
			<u-button class="u-btn" type="primary" @click="addPersonInvolved">
				添加
			</u-button>
		</view>
	</view>
</template>

<script>
	import MeTable from '@/components/me-table.vue';
	import MescrollMoreMixin from "@/components/mescroll-uni/mixins/mescroll-more.js";
	import listItemPerson from './listItemPerson';
	import intelligenceservice from "@/service/intelligence/intelligence.service";
	import fabButton from '@/components/uni-fab.vue';

	export default {
		components: {
			MeTable,
			fabButton,
			listItemPerson,
		},
		mixins: [MescrollMoreMixin, ],
		data() {
			return {
				keyword: "",
				selectedUids: [], // 选中项的ids
				selectedItems: [], // 选中项
				objInfo: {},
				defaultOrg: undefined,
				type: undefined,
				orgName: "",
				orgUuid: "",
				fContent: [{
					iconPath: require('@/static/confirm.png'),
					selectedIconPath: require('@/static/confirm.png'),
					text: '确定',
					active: false,
				}],
			};
		},
		onLoad(opt) {
			this.type = opt.type;
		},
		methods: {
			setRightBtns() {
				// #ifdef H5-DINGDING
				// 先放开右侧标题
				this.$deviceApi.setRight("确定", () => {
					// 点击确定操作
					this.handlerSure();
					this.setRightBtns();
				}, true, true);
				// #endif
			},
			fabtrigger(btn) {
				if (btn.index == 0) {
					this.handlerSure();
				}
			},
			handlerSearch() {
				this.$refs['mescrollItem0'].refresh();
			},
			// 选中
			handlerSelectItem(item) {
				this.selectedUids = [item.uuid, ];
				this.selectedItems = [item, ];
			},
			// 在线案件查询数据
			loadData(page) {
				return new Promise((resolve, reject) => {
					let params = {
						page: page.num,
						limit: page.size,
						paras: {
							fuzzyQuery: this.keyword,
						},
					}
					if (this.defaultOrg) {
						params.paras.orgUuid = this.defaultOrg.id;
						intelligenceservice.personInfoPage(params).then(res => {
							if (res.success) {
								res.data.forEach(itm => {
									itm.show = false;
									itm.swiperDisabled = false;
								});
								resolve({
									count: res.count,
									data: res.data,
								});
							} else {
								this.$u.toast(res.msg);
								resolve({
									count: 0,
									data: [],
								});
							}
						}).catch(e => {
							this.$u.toast('请求失败:' + e);
							resolve({
								count: 0,
								data: [],
							});
						});
					} else {
						this.getDefaultOrg("", "zm-all", (r) => {
							if (r) {
								this.defaultOrg = r;
								this.orgName = r.name;
								this.orgUuid = r.id;
								params.paras.orgUuid = this.defaultOrg.id;
							} else {
								params.paras.orgUuid = "";
							}
							intelligenceservice.personInfoPage(params).then(res => {
								if (res.success) {
									res.data.forEach(itm => {
										itm.show = false;
										itm.swiperDisabled = false;
									});
									resolve({
										count: res.count,
										data: res.data,
									});
								} else {
									this.$u.toast(res.msg);
									resolve({
										count: 0,
										data: [],
									});
								}
							}).catch(e => {
								this.$u.toast('请求失败:' + e);
								resolve({
									count: 0,
									data: [],
								});
							});
						});
					}
				})
			},
			addPersonInvolved() {
				this.$u.route({
					url: "pages/intelligence/intelligenceFilesAdd/personsInvolved",
					params: {
						orgName: this.orgName,
						orgUuid: this.orgUuid,
					},
				});
			},
			updateBackState() {
				this.$refs['mescrollItem0'].refresh();
			},
			// 确定
			handlerSure() {
				let self = this;
				if (this.selectedItems.length == 0) {
					this.$u.toast("请选择关联人员");
					return;
				}
				if (this.type == 1) {
					this.backPrev({
						paramKey: 'refresh',
						param: this.selectedItems,
					})
				} else {
					this.backPrev({
						paramKey: 'hold',
						param: this.selectedItems,
					})
				}
			},
		},
	};
</script>

<style lang="scss" scoped>
	@import "@/style/common/rightMenu.scss";

	.page {
		padding: 0;
	}

	.u-page {
		padding-bottom: 100rpx;
	}

	.nolicence-search-lay {
		background-color: #fff;
		position: fixed;
		// #ifndef H5-DINGDING
		top: 44px;
		// #endif
		// #ifdef H5-DINGDING
		top: 0px;
		// #endif
		z-index: 999;
		width: 100%;
		overflow: hidden;
		padding: $cm-search-padding-row $cm-search-padding-column;
	}
</style>
